package 尚硅谷.juc.test5;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

public class Test5 {


    static AtomicInteger atomicInteger=new AtomicInteger(5);
    public static void main(String[] args) {

        /**
         * CAS就是：比较并交换
         * compareAndSet(期望值，更新值)
         * compareAndSet方法会拿期望值和主内存中的值进行比较，要是期望值和主内存的值相等
         * 则修改主内存中的值，并返回true,若不相等则不修改并返回false
         */
        boolean b = atomicInteger.compareAndSet(5, 10);
        boolean b1 = atomicInteger.compareAndSet(5, 8);
        System.out.println(b);
        System.out.println(b1);
        System.out.println(atomicInteger.get());
    }
}
